package com.zc.app.shiro.realm;

import org.apache.shiro.authc.*;
import org.apache.shiro.realm.Realm;

/**
 * Created by zc on 2016/7/13.
 */
public class MyRealm4 implements Realm {

    @Override
    public String getName() {
        return "myRealm4";
    }

    @Override
    public boolean supports(AuthenticationToken token) {
        return token instanceof UsernamePasswordToken;
    }

    @Override
    public AuthenticationInfo getAuthenticationInfo(AuthenticationToken token) throws AuthenticationException {
        String userName = (String) token.getPrincipal();
        String passwd = String.valueOf((char[])token.getCredentials());

        if(!"zhang".equals(userName)){
            throw new UnknownAccountException();
        }
        if(!"123".equals(passwd)){
            throw new IncorrectCredentialsException();
        }
        return new SimpleAuthenticationInfo(userName,passwd,getName());
    }
}
